package reflectExample;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectExampleTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //1.加载配置文件
        //1.1创建Properties对象
        Properties properties=new Properties();
        ClassLoader classLoader = ReflectExampleTest.class.getClassLoader();
        //注意maven项目配置文件要放在Resources下
        InputStream resource = classLoader.getResourceAsStream("pro.properties");
        properties.load(resource);
        //2.获取配置文件中定义的数据
        String className = properties.getProperty("className");
        String methodName =properties.getProperty("methodName");
        //3.加载该类进内存
        Class aClass = Class.forName(className);
        //4.创建对象
        Object o = aClass.newInstance();
        //5.获取方法对象
        Method method = aClass.getMethod(methodName,int.class);
        //6.执行方法
        method.invoke(o,9);

    }
}
